package com.epam.command.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.epam.command.logic.Command;
import com.epam.command.logic.ManagerLogic;
import com.epam.util.ConfigurationManager;

public class UpdateLastMinuteCommand implements Command {

	
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		int id = Integer.parseInt(request.getParameter("id"));
		String lastMinute = request.getParameter("lastMinute");
		int cost = Integer.parseInt(request.getParameter("cost"));
		String page = ConfigurationManager.getConfig(ConfigurationManager.OPERATION_SUCCESSFUL);
		
		if (ManagerLogic.updateLastMinute(id, lastMinute, cost)) {
			
			request.setAttribute("message", "Operation successful");
		} else {
			
			request.setAttribute("message", "Voucher not found");
		}
		
		return page;
	}

}